<template>
  <a-card class="info" :title="title">
    <a-row type="flex" justify="center">
      <!-- 费用报销申请单 -->
      <a-col :span="24" v-if="billType == '1'">
        <erp-finance-reimbursement-bill-form ref="realForm" :disabled="true" normal :detail="true"></erp-finance-reimbursement-bill-form>
      </a-col>
      <!-- 差旅报销单 -->
      <a-col :span="24" v-else-if="billType == '2'">
        <erp-finance-travel-reimbursement-bill-form ref="realForm" :detail="true" :disabled="true" normal></erp-finance-travel-reimbursement-bill-form>
      </a-col>
      <!-- 付款申请单 -->
      <a-col :span="24" v-else-if="billType == '3'">
        <erp-finance-payment-slip-form ref="realForm" :disabled="true" normal></erp-finance-payment-slip-form>
      </a-col>
      <!-- 保证金申请单 -->
      <a-col :span="24" v-else-if="billType == '4'">
        <erp-finance-project-deposit-bill-form ref="realForm" :disabled="true" normal></erp-finance-project-deposit-bill-form>
      </a-col>
      <!-- 借款申请单 -->
      <a-col :span="24" v-else-if="billType == '5'">
        <erp-finance-loan-bill-form ref="realForm" :disabled="true" :borrowMoneyFlag="false" normal></erp-finance-loan-bill-form>
      </a-col>
    </a-row>
    <!-- 流程历史跟踪 -->
    <common-flow-list v-if="model.bpmStatus !== '1'" :formData="formData"></common-flow-list>
  </a-card>
</template>

<script>

  import { getAction } from '@/api/manage'
  import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
  import ErpFinanceTravelReimbursementBillForm from '@/views/erp/finance/travel/modules/ErpFinanceTravelReimbursementBillForm' // 差旅报销申请单据
  import ErpFinanceReimbursementBillForm from '@/views/erp/finance/reimbursement/modules/ErpFinanceReimbursementBillForm' // 费用申请单据
  import ErpFinancePaymentSlipForm from '@/views/erp/finance/payment/modules/ErpFinancePaymentSlipForm' // 付款申请单据
  import ErpFinanceProjectDepositBillForm from '@/views/erp/finance/deposit/modules/ErpFinanceProjectDepositBillForm' // 保证金单据
  import ErpFinanceLoanBillForm from '@/views/erp/finance/borrow/modules/ErpFinanceLoanBillForm' // 借款单据
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import CommonFlowList from '@/views/components/CommonFlowList.vue' // 审批历史流程列表组件
  export default {
    name: 'ErpFinancePaymentAgainstDocumentsRecordDetail',
    mixins: [JeecgBpmListMixin, DisabledAuthFilterMixin],
    components: {
      ErpFinanceTravelReimbursementBillForm,
      ErpFinanceReimbursementBillForm,
      ErpFinancePaymentSlipForm,
      ErpFinanceProjectDepositBillForm,
      ErpFinanceLoanBillForm,
      CommonFlowList,
    },
    data () {
      return {
        title: '财务交单记录表',
        timer: null,
        labelCol: {
        },
        billType: '', // 類型
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 }
        },
        model: {},
        id: '',
        url: {
          queryById: '/api/erp/finance/reimbursement/erpFinanceReimbursementBill/queryById',
          delete: '/api/erp/finance/reimbursement/erpFinanceReimbursementBill/delete',
          bizCount: '/api/erp/finance/reimbursement/erpFinanceReimbursementBill/bizCount'
        },
        confirmLoading: false,
        iconStyle: { 'font-size': '20px' },
        // 代码生成后需手动设置流程编码
        flowCode: 'onl_erp_finance_reimbursement_bill',
        formUrl: '/erp/finance/reimbursement/modules/ErpFinanceReimbursementBillForm',
        formUrlMobile: ''
      }
    },
    created() {
    },
    watch: {
      $route(to, from) {
        this.loadData();
      },
    },
    mounted() {
    },
    methods: {
      loadData() {
        const arr = this.$route.params.id?this.$route.params.id.split('&'): []
        const billType = arr[0]?arr[0]:'';
        this.billType = billType
        var id = arr[1]?arr[1]:'';
        // 判断单据是什么单据
        if (billType == '1') {
          // 费用报销
          this.title = '费用报销申请记录表'
          this.url = {
            queryById: '/api/erp/finance/reimbursement/erpFinanceReimbursementBill/queryById',
            delete: '/api/erp/finance/reimbursement/erpFinanceReimbursementBill/delete',
            bizCount: '/api/erp/finance/reimbursement/erpFinanceReimbursementBill/bizCount'
          }
          // 代码生成后需手动设置流程编码
          this.flowCode = 'onl_erp_finance_reimbursement_bill',
          this.formUrl = '/erp/finance/reimbursement/modules/ErpFinanceReimbursementBillForm',
          this.formUrlMobile = ''
        } else if (billType == '2') {
          // 差旅报销
          this.title = '差旅报销申请记录表'
          this.url = {
            queryById: '/api/erp/finance/travel/erpFinanceTravelReimbursementBill/queryById',
            delete: '/api/erp/finance/travel/erpFinanceTravelReimbursementBill/delete',
            bizCount: '/api/erp/finance/travel/erpFinanceTravelReimbursementBill/bizCount'
          }
          // 代码生成后需手动设置流程编码
          this.flowCode = 'onl_erp_finance_travel_reimbursement_bill',
          this.formUrl = '/erp/finance/travel/modules/ErpFinanceTravelReimbursementBillForm',
          this.formUrlMobile = ''
        } else if (billType == '3') {
          // 付款申请
          this.title = '付款申请记录表'
          this.url = {
            queryById: '/api/erp/finance/payment/erpFinancePaymentSlip/queryById',
            delete: '/api/erp/finance/payment/erpFinancePaymentSlip/delete',
            bizCount: '/api/erp/finance/payment/erpFinancePaymentSlip/bizCount'
          }
          // 代码生成后需手动设置流程编码
          this.flowCode = 'onl_erp_finance_payment_slip',
          this.formUrl = '/erp/finance/payment/modules/ErpFinancePaymentSlipForm',
          this.formUrlMobile = ''
        } else if (billType == '4') {
          // 保证金申请
          this.title = '保证金申请记录表'
          this.url = {
            queryById: '/api/erp/finance/deposit/erpFinanceProjectDepositBill/queryById',
            delete: '/api/erp/finance/deposit/erpFinanceProjectDepositBill/delete',
            bizCount: '/api/erp/finance/deposit/erpFinanceProjectDepositBill/bizCount'
          }
          // 代码生成后需手动设置流程编码
          this.flowCode = 'onl_erp_finance_project_deposit_bill',
          this.formUrl = '/erp/finance/deposit/modules/ErpFinanceProjectDepositBillForm',
          this.formUrlMobile = ''
        } else if (billType == '5') {
          // 借款申请
          this.title = '借款申请记录表'
          this.url = {
            queryById: '/api/erp/finance/borrow/erpFinanceLoanBill/queryById',
            delete: '/api/erp/finance/borrow/erpFinanceLoanBill/delete',
            bizCount: '/api/erp/finance/borrow/erpFinanceLoanBill/bizCount'
          }
          // 代码生成后需手动设置流程编码
          this.flowCode = 'onl_erp_finance_loan_bill',
          this.formUrl = '/erp/finance/borrow/modules/ErpFinanceLoanBillForm',
          this.formUrlMobile = ''
        }
        
        getAction(this.url.queryById, { id }).then((res) => {
          if (res.success) {
            const model = res.result
            this.$refs.realForm.edit(model);
            this.model = model;
            // 查询流程
            let params = { flowCode: this.flowCode, dataId: id };// 查询条件
            getAction('/api/erpmng/act/process/extActProcessNode/getBizHisProcessNodeInfo', params).then((res) => {
              console.log('--viewTrack', res)
              if (res.success) {
                var data = {
                  dataId: res.result.dataId,
                  procInsId: res.result.procInsId,
                  tableName: res.result.tableName,
                  vars: res.result.records
                }
                this.formData = data;
                this.path = res.result.formUrl;
                if (this.$refs.bizHisTask) {
                  this.$refs.bizHisTask.getHisProcessTaskTransInfo(this.formData);
                }
                
              }
            }).catch(err => {
              console.log('err', err)
            })
          }
        })
        // this.bizCountById(id);
      },
    }
  }
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';

.info {
  /deep/ .ant-card-head-title{
    flex: none;
    margin-right: 20px;
  }
  /deep/ .ant-card-extra{
    flex: 1;
    float: left;
  }
}
</style>
